CLASS zcl_aoc_check_71 DEFINITION
  PUBLIC
  INHERITING FROM zcl_aoc_super
  CREATE PUBLIC .

  PUBLIC SECTION.

    METHODS constructor .

    METHODS check
        REDEFINITION .
    METHODS get_attributes
        REDEFINITION .
    METHODS if_ci_test~query_attributes
        REDEFINITION .
    METHODS put_attributes
        REDEFINITION .
  PROTECTED SECTION.

    DATA mv_unreachable TYPE sap_bool .
  PRIVATE SECTION.
ENDCLASS.



CLASS ZCL_AOC_CHECK_71 IMPLEMENTATION.


  METHOD check.

* abapOpenChecks
* https://github.com/larshp/abapOpenChecks
* MIT License

    DATA: lt_statements TYPE zcl_aoc_scan=>ty_statements,
          lv_index      TYPE i,
          lv_code       TYPE sci_errc,
          ls_prev       LIKE LINE OF lt_statements.

    FIELD-SYMBOLS: <ls_statement> LIKE LINE OF lt_statements.

    lt_statements = io_scan->build_statements( ).

    LOOP AT lt_statements ASSIGNING <ls_statement>.
      lv_index = sy-tabix - 1.
      CLEAR ls_prev.
      READ TABLE lt_statements INDEX lv_index INTO ls_prev. "#EC CI_SUBRC

      FIND REGEX 'MESSAGE.ID.SY-MSGID.TYPE.SY-MSGTY.NUMBER.SY-MSGNO.WITH.SY-MSGV.' IN <ls_statement>-str.
      IF sy-subrc <> 0.
        CONTINUE.
      ENDIF.

      IF <ls_statement>-str CP 'MESSAGE *'
          AND ( ( mv_unreachable = abap_true AND ls_prev-str = 'IF 1 = 2' )
          OR ( mv_unreachable = abap_true AND ls_prev-str = 'IF 0 = 1' ) ).
        CONTINUE.
      ENDIF.

      IF <ls_statement>-str CP 'MESSAGE *'.
        lv_code = '001'.
      ELSE.
        CONTINUE.
      ENDIF.

      inform( p_sub_obj_name = <ls_statement>-include
              p_line         = <ls_statement>-start-row
              p_kind         = mv_errty
              p_test         = myname
              p_code         = lv_code ).
    ENDLOOP.

  ENDMETHOD.


  METHOD constructor.

    super->constructor( ).

    version     = '001'.
    position    = '071'.

    has_attributes = abap_true.
    attributes_ok  = abap_true.

    enable_rfc( ).

    mv_unreachable = abap_true.

    insert_scimessage(
        iv_code = '001'
        iv_text = 'MESSAGE using standard variables from SY structure'(m01) ).

  ENDMETHOD.


  METHOD get_attributes.

    EXPORT
      mv_errty = mv_errty
      mv_unreachable = mv_unreachable
      TO DATA BUFFER p_attributes.

  ENDMETHOD.


  METHOD if_ci_test~query_attributes.

    zzaoc_top.

    zzaoc_fill_att mv_errty 'Error Type' ''.                "#EC NOTEXT
    zzaoc_fill_att mv_unreachable 'Allow unreachable' 'C'.  "#EC NOTEXT

    zzaoc_popup.

  ENDMETHOD.


  METHOD put_attributes.

    IMPORT
      mv_errty = mv_errty
      mv_unreachable = mv_unreachable
      FROM DATA BUFFER p_attributes.                 "#EC CI_USE_WANTED
    ASSERT sy-subrc = 0.

  ENDMETHOD.
ENDCLASS.
